package com.example.department.Controller;

import com.example.department.Entity.Activity;
import com.example.department.Entity.ResultEntity;
import com.example.department.Service.ActivityService;
import com.example.department.Util.JSONTool;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin //解决跨域问题
@RestController
@RequestMapping("/Activity/") //路径
public class ActivityController {
    @Resource
    ActivityService activityService;
    ResultEntity resultEntity=null;
    @GetMapping("ActivityList")
    private String ActivityList(
            @RequestParam("page") int page,
            @RequestParam("limit") int limit,
            @RequestParam("activityname")String activityname,
            @RequestParam("activityaddress") String activityaddress
    ){
        try {
            resultEntity = new ResultEntity();
            int Start = (page-1) * limit; //计算起始位置
            List<Activity> list = activityService.getActivityPageList(activityname,activityaddress,Start,limit);
            if ( !activityname.equals("") || !activityaddress.equals("")){
                resultEntity.setCount(list.size());
//                resultEntity.setCount(mes.getMessageCount());
            }else {
                resultEntity.setCount(activityService.getActivityCount());
            }
            resultEntity.setCode("200");
            resultEntity.setData(list);
            resultEntity.setMsg("查询成功!");
        }catch (Exception e){
            e.printStackTrace();
            resultEntity.setCode("999");
            resultEntity.setMsg("查询失败!"+e.getMessage());
        }
        return JSONTool.getJsonTool().toJson(resultEntity);
    } 
}
